package com.he.controller;

import com.he.entity.Hotel;
import com.he.entity.ResultData;
import com.he.entity.SearchInfo;
import com.he.service.ISearchService;
import com.he.service.impl.SearchServiceImpl;
import org.elasticsearch.search.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private ISearchService searchService;

    @RequestMapping("/list")
    public ResultData<List<Hotel>> searchHotel(SearchInfo searchInfo){
        //System.out.println("搜索的内容为"+searchInfo);
        List<Hotel> hotels = searchService.searchByKeyWord(searchInfo);
        System.out.println("搜索的结果--------" + hotels.size());
        hotels.stream().forEach(hotel -> {
            System.out.println("---------------------------------------");
            System.out.println(hotel);
        });
        return new ResultData<List<Hotel>>().setData(hotels);
    }
}
